/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.test_instantiator;

import picounit.features.Feature;
import picounit.features.base.FeatureRegistry;
import picounit.features.base.Migration;
import picounit.features.class_finder.ClassFinder;
import picounit.features.registry.RegistryFactory;
import picounit.features.signature_factory.SignatureFactoryFactory;

public class TestInstantiatorFeature implements Feature {
	private final SignatureFactoryFactory signatureFactoryFactory;
	private final ClassLoader classLoader;
	private final ClassFinder classFinder;
	private final RegistryFactory registryFactory;

	public TestInstantiatorFeature(SignatureFactoryFactory signatureFactoryFactory, ClassFinder classFinder,
		ClassLoader classLoader, RegistryFactory registryFactory) {

		this.signatureFactoryFactory = signatureFactoryFactory;
		this.classFinder = classFinder;
		this.classLoader = classLoader;
		this.registryFactory = registryFactory;
	}

	public void addFeatures(FeatureRegistry featureRegistry) {
		final TestInstantiator testInstantiator = DefaultTestInstantiator.create(
			signatureFactoryFactory.create(registryFactory.create()), classLoader, classFinder);

		featureRegistry.addFeatures(testInstantiator); 

		featureRegistry.migrate(TestInstantiator.class, new Migration<TestInstantiator>() {
			public TestInstantiator migrate(TestInstantiator original) {
				return testInstantiator;
			}
		});
	}
}
